package main

import (
	"sort"
)

/*
 * @lc app=leetcode.cn id=23 lang=golang
 *
 * [23] 合并K个升序链表
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */

func mergeKLists(lists []*ListNode) *ListNode {
	var ints []int
	for _, node := range lists {
		for node != nil {
			ints = append(ints, node.Val)
			node = node.Next
		}
	}
	sort.Ints(ints)
	var head = &ListNode{}
	cur := head
	for _, v := range ints {
		cur.Next = &ListNode{
			Val: v,
		}
		cur = cur.Next
	}
	return head.Next
}

// @lc code=end
